package com.donkeyx.pattern.factory.factorymethod;

import com.donkeyx.pattern.factory.Graphical;
import com.donkeyx.utils.ConfigUtil;


public class Test {

    public static void main(String[] args) {
        System.out.println("---------------------------------使用默认方式进行创建----------------------------------");
        defaultMethod();
        System.out.println("---------------------------------读取配置文件方式进行动态创建----------------------------------");
        readConfigFile();
    }


    /**
     * 使用默认方式进行创建
     */
    public static void defaultMethod(){
        //创建一个圆形
        GraphicalFactory factory;
        factory = new CircularGraphicalFactory();
        Graphical circular = factory.createGraphical();
        circular.draw();
        circular.erase();
        //创建一个三角形
        factory = new TriangleGraphicalFactory();
        Graphical triangle = factory.createGraphical();
        triangle.draw();
        triangle.erase();
    }


    /**
     * 读取配置文件方式进行动态创建
     */
    public static void readConfigFile() {
        GraphicalFactory factory;
        factory = (GraphicalFactory)ConfigUtil.getBean();
        Graphical graphical = factory.createGraphical();
        graphical.draw();
        graphical.erase();
    }
}
